﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Dictionary.Vendor;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlVendorList : BaseListUserControl, IVendorsView  
    {
        private readonly VendorsPresenter _vendorsPresenter;  

        public UserControlVendorList()
        {
            InitializeComponent();
            _vendorsPresenter = new VendorsPresenter(this);
        }

        /// <summary>
        /// Deletes the grid.
        /// </summary>
        protected override string DeleteGrid()
        {
            return new VendorPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }

        /// <summary>
        /// Loads the data into grid.
        /// </summary>
        protected override void LoadDataIntoGrid(int page)
        {
            TotalPage = _vendorsPresenter.GetPageSize();
            if (page <= TotalPage)
            {
                _vendorsPresenter.Display(page);
            }
        }

        public IList<Model.BusinessObjects.Dictionary.VendorModel> Vendors
        {
            set
            {
                ListBindingSource.DataSource = value;
                gridView.PopulateColumns(value);

                ColumnsCollection.Add(new XtraColumn { ColumnName = "VendorId", ColumnVisible = false, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Code", ColumnCaption = "Mã NCC", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 50 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Name", ColumnCaption = "Họ tên", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 200 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Address", ColumnCaption = "Địa chỉ", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 150 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsActive", ColumnCaption = "Ngừng theo dõi", ColumnPosition = 5, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "ContactName", ColumnVisible = false });

                ColumnsCollection.Add(new XtraColumn { ColumnName = "PhoneNumber", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Fax", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Description", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitId", ColumnVisible = false });
            }
        }
    }
}
